#include<vector>
#include<stack>

#include<iostream>
using namespace std;

class Solution
{
public:
	bool IsPopOrder(vector<int>& pushV, vector<int>& popV)
	{
		int pushi = 0, popi = 0;
		stack<int> st;

		while (pushi < pushV.size())
		{
			st.push(pushV[pushi++]);

			while (!st.empty() || popV[popi] == st.top())
			{
				popi++;
				st.pop();
			}
		}

		return st.empty();
	}
};